<!DOCTYPE html>
<html style="height: 100%">
<head>
    <title>修改密码页面</title>
    <% include layouts/import.ejs %>
</head>
<body style="height: 100%">
<% include layouts/header.ejs %>
<div class="height" style="background: #F8F6F2;padding-top: 42px;">

    <div class="container main-content" >
        <div class="row">

            <div class="person-content">
                <input type="hidden" value="<%= id %>"   name="id"/>
                <div class="form-group">
                    <label class="control-label">用户名<span style="color:red;font-weight:bolder">*</span></label>
                    <input type="text" value="<%= loginName %>"   id="loginName" name="loginName" class="form-control"
                           data-provide="typeahead" readonly autocomplete="false"/>
                </div>

                <!--<div class="form-group">-->
                    <!--<label class="control-label">密码<span style="color:red;font-weight:bolder">*</span></label>-->
                    <!--<input type="text" value="<%= password %>" readonly  id="password" name="password"-->
                           <!--class="form-control"/>-->
                <!--</div>-->

                <div class="form-group">
                    <label class="control-label">新密码<span style="color:red;font-weight:bolder">*</span></label>
                    <input type="text"   value="<%= newPassword %>"  id="newPassword" name="newPassword"
                           class="form-control"/>
                </div>

                <div class="form-group">
                    <label class="control-label">确认密码<span style="color:red;font-weight:bolder">*</span></label>
                    <input type="text"    value="<%= confirmPassword %>"  id="confirmPassword" name="confirmPassword"
                           class="form-control"/>
                </div>
            </div>

                <div class="form-button">
                    <button type="submit" class="person-preservation btn btn-primary" id="submit">保存</button>
                    <button type="button" data-dismiss="modal" id="return" class="btn btn-default" style="margin-left: 3%">返回</button>
                </div>

        </div>
    </div>



    <% include layouts/footer.ejs %>
</div>
</body>

<script>
    $(function () {
        $("#activity").addClass("click-change")
        $('#return').click(function () {
            location.href = '/index';
        });

        $('#submit').click(function () {
            var loginName = $('#loginName').val();
            var newPassword = $('#newPassword').val();
            var confirmPassword = $('#confirmPassword').val();
            var html = '';
            html += '<div class="login-error-message"> ' + "两次输入密码不一致" + '</div>'
            if (newPassword === confirmPassword) {
                $.post('/password/save', {
                    loginName: loginName,
                    newPassword: newPassword,
                    confirmPassword: confirmPassword
                }, function (result) {
                    console.log(result);
                    if (result.errcode === 0) {
                        location.href = '/index';
                    } else {
                        location.href = '/login';
                    }
                });

            } else {
                $('.person-content').append(html)
            }


        });
    })
</script>
</html>